extends CenterContainer


var edit_data = null

onready var item_op = $PanelContainer/VBoxContainer/item/ItemSelect

onready var count_input = $PanelContainer/VBoxContainer/count/SpinBox
onready var repeat_op = $PanelContainer/VBoxContainer/aRepeat/OptionButton

signal close


func set_edit_data(data):
	self.edit_data = data
	
	if edit_data:
		item_op.set_value(data["itemId"])
		count_input.value = data["count"]

		repeat_op.select(repeat_op.get_item_index(data["aRepeat"]))
	

func _on_cancel_button_up():
	MainTool.getUILayer().pop_ui()


func _on_ok_button_up():
	if edit_data:
		edit_data["itemId"] = item_op.get_value()
		edit_data["aRepeat"] = repeat_op.get_selected_id()
		edit_data["count"] = count_input.value
			
		DataSource.update_data(DataSource.pick_item, edit_data)
		
		MainTool.toast_info("更新成功!")
	else:
		var data = {
			"itemId": item_op.get_value(),
			"aRepeat": repeat_op.get_selected_id(),
			"count": count_input.value,
		}
		
		DataSource.add_data(DataSource.pick_item, data)
	
		MainTool.toast_info("添加成功!")
	
	MainTool.getUILayer().pop_ui()
	
	emit_signal("close")
